import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import { TUIComponents, TUIChatKit } from "./TUIKit";
import { TUIStore, StoreName, TUITranslateService } from "@tencentcloud/chat-uikit-engine";
import TUINotification from "./TUIKit/components/TUINotification/index";
import { locales } from "./locales";
import TencentCloudChat from "@tencentcloud/chat";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";

// ------ The following is the introduction of TUIRoom related dependencies. If you do not need to use TUIRoom, please delete the following code ------
import { createPinia } from "pinia";
// ----------------------------------------------------------------------------
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";

import * as echarts from "echarts";
const app = createApp(App);

app.config.globalProperties.$echarts = echarts;

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.use(router);
// ------ The following is the introduction of TUIRoom related dependencies. If you do not need to use TUIRoom, please delete the following code ------
app.use(createPinia());
// ----------------------------------------------------------------------------
app.use(ElementPlus, {
  locale: zhCn,
});
app.mount("#app");

const SDKAppID = 1600056022; // Your SDKAppID
// const SDKAppID = 1600063829;

TUIChatKit.components(TUIComponents, app);

TUITranslateService.provideLanguages(locales);
TUITranslateService.useI18n();

let options = {
  SDKAppID: SDKAppID,
};
const Chat = TencentCloudChat.create(options);

/**
 * Init TUINotification configuration.
 */
TUINotification.setNotificationConfiguration({
  showPreviews: true,
  allowNotifications: true,
  notificationTitle: "Tencent Cloud Chat",
  notificationIcon: "https://web.sdk.qcloud.com/im/demo/latest/faviconnew.png",
});

Chat.setLogLevel(4);

/**
 * Listen for new messages and use notification components.
 * This capability is only available in the web environment.
 */
TUIStore.watch(StoreName.CHAT, {
  newMessageList: (newMessageList: unknown) => {
    if (Array.isArray(newMessageList)) {
      newMessageList.forEach(message => TUINotification.notify(message));
    }
  },
});

export { SDKAppID, Chat };
